//gsa查询
import { FileServerProxy } from '@/utils/api'
import { Toast } from 'vant';
export const GSA_Search = async(dataguid,data1) => {
    let data = {
        accessCode: '688bd3883572440a859dfd8ba9194e7b',
        cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        params: {
            dataguid: dataguid,
            searchObject: JSON.stringify(data1),
            token: window.localStorage.getItem('token'),
        },
    }
    const res = await FileServerProxy(data)
    return JSON.parse(res.data.data)
}
export const GSA_Search1 = async(dataguid,data1) => {
    let data = {
        accessCode: '688bd3883572440a859dfd8ba9194e7b',
        cityCode: window.localStorage.getItem('citycodeChange') ? window.localStorage.getItem('citycodeChange') : '441300000000',
        params: {
            dataguid: dataguid,
            searchObject: JSON.stringify(data1),
            token: window.localStorage.getItem('token'),
        },
    }
    const res = await FileServerProxy(data)
    return JSON.parse(res.data.data)
}
export const GSA_Search2 = async(dataguid,data1,citycode) => {
    let data = {
        accessCode: '688bd3883572440a859dfd8ba9194e7b',
        cityCode: citycode,
        params: {
            dataguid: dataguid,
            searchObject: JSON.stringify(data1),
            token: window.localStorage.getItem('token'),
        },
    }
    const res = await FileServerProxy(data)
    return JSON.parse(res.data.data)
}

//gsa新增
export const GSA_Add = async(dataGuid,isAdd,data1) => {
    let params = {
        accessCode: '',
        cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        params: {
            dataGuid: dataGuid,
            strParams: JSON.stringify([data1]),
            token: window.localStorage.getItem('token')
        }
    }
    if (isAdd) {
        params.accessCode = '0fb3f6123d1b4fe6851c99532c463f6f'
        const res = await FileServerProxy(params)
        let data = JSON.parse(res.data.data).Success
        if (data) {
            Toast.success('成功！')
        } else {
            Toast.fail('失败！')
        }
        return data
    } else {
        params.accessCode = '77ad6c1591e54d4fbc45ecc90374a2a2'
        const res = await FileServerProxy(params)
        let data = JSON.parse(res.data.data).Success
        if (data) {
            Toast.success('修改成功!')
        } else {
            Toast.fail('修改失败！')
        }
        return data
    }
}
export const GSA_Add1 = async(dataGuid,isAdd,data1) => {
    let params = {
        accessCode: '',
        cityCode: window.localStorage.getItem('citycodeChange') ? window.localStorage.getItem('citycodeChange') : '441300000000',
        params: {
            dataGuid: dataGuid,
            strParams: JSON.stringify([data1]),
            token: window.localStorage.getItem('token')
        }
    }
    if (isAdd) {
        params.accessCode = '0fb3f6123d1b4fe6851c99532c463f6f'
        const res = await FileServerProxy(params)
        let data = JSON.parse(res.data.data).Success
        if (data) {
            Toast.success('成功！')
        }
    } else {
        params.accessCode = '77ad6c1591e54d4fbc45ecc90374a2a2'
        const res = await FileServerProxy(params)
        let data = JSON.parse(res.data.data).Success
        if (data) {
            Toast.success('修改成功!')
        }
    }
}
/**
 * @param {Date}
 * this.addDate('2023-03-28 12:00')
 */
export const addDate = (time) => {
    //加一天
    //日期格式
    Date.prototype.format = function (format) {
      var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
      };
      if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
          format = format.replace(RegExp.$1, RegExp.$1.length == 1
            ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
      }
      return format;
    }
    var timestamp = Date.parse(new Date(time));
    timestamp = timestamp / 1000;
    timestamp += 86400;//加一天
    var newTime = new Date(timestamp * 1000).format('yyyy-MM-dd hh:mm:ss');
    return newTime;
  }